package com.springcloud.eureka_consumer.contorller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.discovery.converters.Auto;
import com.springcloud.eureka_consumer.remote.interfaces.UserRemoteI;

/**
 * @author hw
 * <p>服务消费者</p>
 */
@RestController
public class UserContorller {

	
	private String url="http://localhost:7000/user/";
	//provider-user是在eureka中注册的服务提供者实例名
	private String provider="http://provider-user/user/";
	private int port=7000;
	
//	@Autowired
//	RestTemplate restTemplate;
	@Autowired
	UserRemoteI userRemote;
	
	@RequestMapping("getUser/{id}")
	public Object getUser(@PathVariable("id") int id) {
//		1.使用restTemplete进行远程调用
//		简单的程序间rest-api调用
//		Object object=restTemplate.getForObject(url+id, Object.class);
//		调用eureka服务
//		Object object=restTemplate.getForObject(provider+id, Object.class);
//		JSONObject jObject=restTemplate.getForObject(url+id, JSONObject.class);
//		System.out.println(jObject);
		
//		2.使用Feign进行远程调用
		Object object=userRemote.getUser(id);
		
		System.out.println(object);
		return object;
		
	}



}
